package org.wang.portal.task;

import org.wang.portal.status.TaskStatus;

import java.util.Map;

public abstract class MigrationTask {
    protected String name;
    protected TaskStatus status;
    protected long startTime;
    protected long endTime;
    protected Map<String, String> config;
    protected DatabaseType sourceDatabaseType;
    protected DatabaseType targetDatabaseType;

    public MigrationTask(String name, Map<String, String> config, DatabaseType sourceDatabaseType, DatabaseType targetDatabaseType) {
        this.name = name;
        this.status = TaskStatus.NOT_STARTED;
        this.config = config;
        this.sourceDatabaseType = sourceDatabaseType;
        this.targetDatabaseType = targetDatabaseType;
    }

    public String getName() {
        return name;
    }

    public TaskStatus getStatus() {
        return status;
    }

    public long getStartTime() {
        return startTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public Map<String, String> getConfig() {
        return config;
    }

    public DatabaseType getSourceDatabaseType() {
        return sourceDatabaseType;
    }

    public DatabaseType getTargetDatabaseType() {
        return targetDatabaseType;
    }

    protected void setStatus(TaskStatus status) {
        this.status = status;
        if (status == TaskStatus.IN_PROGRESS) {
            this.startTime = System.currentTimeMillis();
        } else if (status == TaskStatus.COMPLETED || status == TaskStatus.FAILED) {
            this.endTime = System.currentTimeMillis();
        }
    }
    public abstract void prepareExecuteEnv();
    public abstract void execute();

    public abstract void pause();

    public abstract void resume();

    public abstract void stop();

    public abstract double getProgress();
}